import { createSlice } from '@reduxjs/toolkit'
// Define the initial state using that type
const initialState = {
  token: '',
  userInfo: {
    app_default: '',
    desktop: '',
    employeeid: '',
    id: '',
    idcard: '',
    is_auth: 0,
    login_error_num: 0,
    login_error_time: 0,
    mobile: '',
    realname: '',
    role_default: '',
  },
  sendTime: 0,
  structureName: ''
}

export const basicSlice = createSlice({
  name: 'basic',
  // `createSlice` will infer the state type from the `initialState` argument
  initialState,
  reducers: {
    setToken: (state, action) => {
      state.token = action.payload
    },
    setUserInfo: (state, action) => {
      state.userInfo = action.payload
    },
    setSendTime: (state, action) => {
      state.sendTime = action.payload
    },
    logout: (state) => {
      state.token = ''
      state.userInfo = JSON.parse(JSON.stringify(initialState.userInfo))
    },
    setStructureName: (state, action) => {
      state.structureName = action.payload
    }
  },
})

export const { setToken, setUserInfo, logout, setSendTime, setStructureName } = basicSlice.actions

export default basicSlice.reducer